/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controller.event;

import com.entities.EventInfo;
import com.entities.EventLibrary;
import com.model.EventLibraryModel;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Tuan Long
 */
@Named(value = "eventContent")
@RequestScoped
public class eventContent {

    public eventContent() {
    }

    @ManagedProperty(value = "#{param.eventId}")
    private String eventId;

    public String getEventId() {
        return eventId;
    }

    public void setEventId(String eventId) {
        this.eventId = eventId;
    }

    private EventLibrary eventinfo;

    public EventLibrary getEventinfo() {
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        eventId = req.getParameter("eventId");
        if (eventId != null) {
            EventLibraryModel model = new EventLibraryModel();
            eventinfo = model.getEventContentById(eventId);            
        }
        return eventinfo;
    }

    private EventInfo eventinfo2;

    public EventInfo getEventinfo2() {
        if (eventId != null) {            
            EventLibraryModel model = new EventLibraryModel();
            eventinfo2 = model.getEventContentById2(eventId);            
        }
        return eventinfo2;
    }

    public void setEventinfo2(EventInfo eventinfo2) {
        this.eventinfo2 = eventinfo2;
    }

    /**
     * *
     * List<EventLibrary> events
     */
    private List<EventLibrary> events;
    private String tag;

    public List<EventLibrary> getEvents() {
        fillEvents();
        return events;
    }

    private void fillEvents() {
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        EventLibraryModel model = new EventLibraryModel();
        if (req.getParameter("tag") != null) {
            tag = req.getParameter("tag");
            switch (tag) {
                case "talk show":
                    events = model.getTop10EventIdAndNameByEventTag("talkshow");
                    break;
                case "game":
                    events = model.getTop10EventIdAndNameByEventTag("game");
                    break;
                case "meeting":
                    events = model.getTop10EventIdAndNameByEventTag("meeting");
                    break;
                case "other":
                    events = model.getTop10EventIdAndNameByEventTag("other");
                    break;
                default:
                    events = model.getTop10EventIdAndName();
                    break;
            }
        } else {
            //events = model.getTop10EventIdAndName();
        }
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }
}
